<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>案例</title>
    <script>
        function observer(data){
            return new Proxy(data,{
                get(target,attr){
                    return target[attr]
                },
                set(target,attr,newValue){
                    target[attr] = newValue;
                    title.innerHTML = newValue;
                }
            });
        }
    </script>
</head>
<body>
    <button id="btn">测试</button>
    <div id="ap">测试</div>
    <script>
        let btn = document.querySelector('#btn');
        let title = document.querySelector('#ap');
        let data = {
            title: 'hello,测试',
            message: 'hello,测试'
        }
        data = observer(data);
        btn.onclick = function(){
            data.title = 'abc'
        }
    </script>
</body>
</html>